/*!
\copyright  Copyright (c) 2021-2022 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\brief
*/

#if defined(INCLUDE_LE_AUDIO_BROADCAST) && defined(ENABLE_LE_AUDIO_RESTRICTED_MULTIPOINT)

#include "le_broadcast_manager_feature.h"
#include "le_broadcast_manager_data.h"

#include "feature_manager.h"

#include <panic.h>


static feature_state_t LeBroadcastManager_GetFeatureState(void)
{
    return le_broadcast_manager.broadcast_feature_state;
}

static const feature_interface_t le_broadcast_feature_if = {
    .GetState = LeBroadcastManager_GetFeatureState,
    .Suspend = NULL,
    .Resume = NULL
};


void LeBroadcastManager_FeatureInit(void)
{
    LeBroadcastManager_SetFeatureHandle(FeatureManager_Register(feature_id_le_broadcast, &le_broadcast_feature_if));
    LeBroadcastManager_SetFeatureState(feature_state_idle);
}

void LeBroadcastManager_FeatureStart(void)
{
    if (feature_state_idle == LeBroadcastManager_GetFeatureState())
    {
        if (FeatureManager_StartFeatureRequest(LeBroadcastManager_GetFeatureHandle()))
        {
            LeBroadcastManager_SetFeatureState(feature_state_running);
        }
        else
        {
            /* The LE Broadcast feature should always be the highest feature
               in a priority list so starting it should never fail. */
            Panic();
        }
    }
}

void LeBroadcastManager_FeatureStop(void)
{
    if (feature_state_running == LeBroadcastManager_GetFeatureState())
    {
        LeBroadcastManager_SetFeatureState(feature_state_idle);
        FeatureManager_StopFeatureIndication(LeBroadcastManager_GetFeatureHandle());   
    }
}

#endif /* defined(INCLUDE_LE_AUDIO_BROADCAST) && defined(ENABLE_LE_AUDIO_RESTRICTED_MULTIPOINT) */
